package com.zhanghu.backendZray.config.rocksDB;

import lombok.extern.slf4j.Slf4j;
import org.rocksdb.Options;
import org.rocksdb.RocksDB;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class RocksDBConfig {

    @Value("${rocksDB.path}")
    private String rocksDBDataPath;

    @Bean(destroyMethod = "close")
    public RocksDB getRocksDB() {
        try {
//            RocksDB.loadLibrary();
            Options options = new Options();
            options.setCreateIfMissing(true);
            return RocksDB.open(options, rocksDBDataPath);
        } catch (Exception e) {
            log.error("rocksDB init error:{}", e);
            return null;
        }
    }
}


